package com.dotflat.fin.service.impl;
 
import com.dotflat.fin.domain.Wallet;
import com.dotflat.fin.repository.WalletRepository;
import com.dotflat.fin.service.WalletService;
import com.dotflat.rest.service.AreableObjectBaseService;
import com.dotflat.rest.service.impl.AreableObjectBaseServiceImpl;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.domain.Clientele;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 钱包service
 *
 * @author ：Ron
 * @date ：Created in 2020/10/30 13:06
 */
@Service
public class WalletServiceImpl extends AreableObjectBaseServiceImpl<Wallet, WalletRepository> implements WalletService {

    @Autowired
    private WalletRepository walletRepository;


    public Wallet queryWalletByClientele(Clientele clientele){
        Wallet w = walletRepository.findFirstByClienteleId(clientele.getId());
        if (w == null){
            w = new Wallet();
            w.setClienteleId(clientele.getId());
            w.setCreatedBy(clientele.getStaffId());
            w.setAreaId(clientele.getAreaId());
            walletRepository.save(w);
        }
        return w;
    }

    @Override
    public Wallet update(Wallet wallet) {
        return walletRepository.save(wallet);
    }

    @Override
    public Integer underWayAmount(StaffDTO user) {
        return null;
    }

    @Override
    public void unfrozenAmount(Wallet wallet, long amountToUnfreezen) {

    }

}
